<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Temperature Spots Information Management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/datepicker/datepicker.js"></script>
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 表单校验 -->
	<jsp:include page="/resources/resource-refer/component-validform-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function formVerify() {
  		var verify = true;
  		//所属项目
  		var projectID = $("select[name='temperaturePoint.projectID']").val();
  		if(projectID == "") {
  			$("select[name='temperaturePoint.projectID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='temperaturePoint.projectID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//所属小区
  		var communityID = $("select[name='temperaturePoint.communityID']").val();
  		if(communityID == "") {
  			$("select[name='temperaturePoint.communityID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='temperaturePoint.communityID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//所属楼栋
  		var buildingID = $("select[name='temperaturePoint.buildingID']").val();
  		if(buildingID == "") {
  			$("select[name='temperaturePoint.buildingID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='temperaturePoint.buildingID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//门牌号
  		var roomId = $("select[name='temperaturePoint.roomId']").val();
  		var houseNo = $("input[name='temperaturePoint.houseNo']").val();
  		if(roomId=="" && (houseNo=="" || $.trim(houseNo)=="")) {
  			$("select[name='temperaturePoint.roomId']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='temperaturePoint.roomId']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//集中器号
  		var concentratorID = $("select[name='temperaturePoint.concentratorID']").val();
  		if(concentratorID == "") {
  			$("select[name='temperaturePoint.concentratorID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("select[name='temperaturePoint.concentratorID']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		//温度点编号
  		var seriousNum = $("input[name='seriousNum']").val();
  		if(seriousNum=="" || isNaN(seriousNum)) {
  			$("input[name='seriousNum']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			verify = false;
  		} else {
  			$("input[name='seriousNum']").parent("td").find("span").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		return verify;
  	}
  
  	function submitForm() {
  		var tempPointUID = "<s:property value='tempPointUID' />";
  		//所属项目
  		var projectID = $("select[name='temperaturePoint.projectID']").val();
  		//所属小区
  		var communityID = $("select[name='temperaturePoint.communityID']").val();
  		//所属楼栋
  		var buildingID = $("select[name='temperaturePoint.buildingID']").val();
  		//门牌号
  		var roomId = $("select[name='temperaturePoint.roomId']").val();
  		var houseNo = $("input[name='temperaturePoint.houseNo']").val();
  		//集中器号
  		var concentratorID = $("select[name='temperaturePoint.concentratorID']").val();
  		//温度点编号
  		var seriousNum = $("input[name='seriousNum']").val();
  		//备注
  		var remark = $("textarea[name='remark']").val();
  		$.getJSON(path+"beshs/temperaturePointActionJson!saveOrUpdateTempPoint.do?date="+new Date(), {
  			"temperaturePoint.id": tempPointUID,
  			"temperaturePoint.projectID": projectID,
  			"temperaturePoint.communityID": communityID,
  			"temperaturePoint.buildingID": buildingID,
  			"temperaturePoint.roomId": roomId,
  			"temperaturePoint.houseNo": houseNo,
  			"temperaturePoint.concentratorID": concentratorID,
  			"temperaturePoint.seriousNum": $.trim(seriousNum),
  			"temperaturePoint.remark": $.trim(remark)
  		}, function(data){
  			if(data.success) {
  				Dialog.alert("Successful Operation！", function() {
  					var index = parent.layer.getFrameIndex(window.name)
					parent.window.frames["c_content_content"].location = path + "beshs/temperaturePointAction!queryTemperaturePointPage.do?date"+new Date();
  					parent.layer.close(index);
  				});
  			} else {
  				Dialog.alert(data.msg);
  			}
  		});
  	}
  	
  	$(function(){
  		$("form[name='tempPointForm']").Validform({
			btnSubmit: "input[name='submit']",
			btnReset: "input[name='reset']",
			ignoreHidden: true, //对hidden的表单元素将不做验证
			tiptype: function(msg, o, cssctl){
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
					var objtip=o.obj.siblings(".Validform_checktip");
					cssctl(objtip,o.type);
					objtip.text(msg);
				} else {
					var objtip=o.obj.find("#msgdemo");
					cssctl(objtip,o.type);
					objtip.text(msg);
				}
			},
			postonce: true, //开启二次提交防御，在数据成功提交后，表单将不能再继续提交
			showAllError: true, //提交表单时所有错误提示信息都会显示
			ajaxPost:true,
			beforeSubmit: function(curform) { //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象
				submitForm();
				return true; //这里明确return false的话表单将不会提交
			}
		});
  		
  		$("a[name='switchLink']").click(function() {
  			if($("a[name='switchLink']").text()=="other"){
  	        	$("select[name='temperaturePoint.roomId']").hide("fast");
  	        	//清空选择的门牌号
  	        	$("select[name='temperaturePoint.roomId']").val("");
  	      		$("input[name='temperaturePoint.houseNo']").show("fast");
  	      		$("a[name='switchLink']").text("select");
  	        } else {
  	        	$("input[name='temperaturePoint.houseNo']").hide("fast");
  	        	//清空人工填写的门牌号
  	        	$("input[name='temperaturePoint.houseNo']").val("");
  	        	$("select[name='temperaturePoint.roomId']").show("fast");
  	        	$("a[name='switchLink']").text("other");
  	        }
  		});
  	});
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#" name="tempPointForm"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      			<tr>
          			<th>Project：</th>
          			<td><s:select name="temperaturePoint.projectID" list="projectList" listKey="id" listValue="projectName" headerKey="" headerValue="Please select" cssClass="s_sel"
          					datatype="*" nullmsg="Please select the project！" errormsg="Please select the project！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
            		<th>District：</th>
          			<td>
          				<script type="text/javascript">
		      				function reloadCommunitys(projectUID, communityUID) {
		      					$("select[name='temperaturePoint.communityID']").children("option").slice(1).remove();
		      					if(projectUID!=null && projectUID!="") {
		      						$.getJSON(path+"beshs/communityActionJson!queryCommunitysByBelongs.do?date="+new Date(), {
		      							projectUID: projectUID
		      						}, function(data){
		      							for(var index=0; index<data.length; index++) {
		      								if(communityUID!=null && communityUID!="" && communityUID==data[index].id) {
			        							$("select[name='temperaturePoint.communityID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].communityName+"</option>");
			        						} else {
			        							$("select[name='temperaturePoint.communityID']").append("<option value='"+data[index].id+"'>"+data[index].communityName+"</option>");
			        						}
		      							}
		      						});
		      					}
		      				}
		      					
		      				$(function() {
		      					$("select[name='temperaturePoint.projectID']").change(function(){
				        			var projectUID = $(this).val();
				        			var communityUID = $("select[name='temperaturePoint.communityID']");
				        			reloadCommunitys(projectUID, communityUID);
				        		});
		      				});
		      			</script>
		      			<s:select name="temperaturePoint.communityID" list="communityList" listKey="id" listValue="communityName" headerKey="" headerValue="Please select" cssClass="s_sel"
		      				datatype="*" nullmsg="Please select the district！" errormsg="Please select the district！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Building：</th>
          			<td>
          				<script type="text/javascript">
				       		function reloadBuildings(projectUID, communityUID, buildingUID) {
			        			$("select[name='temperaturePoint.buildingID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/buildingActionJson!queryBuildingsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(buildingUID!=null && buildingUID!="" && buildingUID==data[index].id) {
	        								$("select[name='temperaturePoint.buildingID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].buildingName+"</option>");
	        							} else {
	        								$("select[name='temperaturePoint.buildingID']").append("<option value='"+data[index].id+"'>"+data[index].buildingName+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		
			        		$(function(){
			        			$("select[name='temperaturePoint.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='temperaturePoint.communityID']").val();
			        				var buildingUID = $("select[name='temperaturePoint.buildingID']").val();
			        				reloadBuildings(projectUID, communityUID, buildingUID);
			        			});
			        			
			        			$("select[name='temperaturePoint.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='temperaturePoint.projectID']").val();
			        				var buildingUID = $("select[name='temperaturePoint.buildingID']").val();
			        				reloadBuildings(projectUID, communityUID, buildingUID);
			        			});
			        		});
			       		</script>
			       		<s:select name="temperaturePoint.buildingID" list="buildingList" listKey="id" listValue="buildingName" headerKey="" headerValue="Please select" cssClass="s_sel"
			       			datatype="*" nullmsg="Please select the building！" errormsg="Please select the building！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
            		<th>Apartment Number：</th>
          			<td>
          				<script type="text/javascript">
			        		function reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID) {
			        			$("select[name='temperaturePoint.roomId']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/heatRoomActionJson!queryHeatRoomsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID,
			        				buildingUID: buildingUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(heatRoomUID!=null && heatRoomUID!="" && heatRoomUID==data[index].id) {
	        								$("select[name='temperaturePoint.roomId']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].houseNo+"</option>");
	        							} else {
	        								$("select[name='temperaturePoint.roomId']").append("<option value='"+data[index].id+"'>"+data[index].houseNo+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		$(function(){
			        			$("select[name='temperaturePoint.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='temperaturePoint.communityID']").val();
			        				var buildingUID = $("select[name='temperaturePoint.buildingID']").val();
			        				var heatRoomUID = $("select[name='temperaturePoint.roomId']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        			
			        			$("select[name='temperaturePoint.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='temperaturePoint.projectID']").val();
			        				var buildingUID = $("select[name='temperaturePoint.buildingID']").val();
			        				var heatRoomUID = $("select[name='temperaturePoint.roomId']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        			
			        			$("select[name='temperaturePoint.buildingID']").change(function(){
			        				var buildingUID = $(this).val();
			        				var projectUID = $("select[name='temperaturePoint.projectID']").val();
			        				var communityUID = $("select[name='temperaturePoint.communityID']").val();
			        				var heatRoomUID = $("select[name='temperaturePoint.roomId']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        		});
			        	</script>
						<s:select name="temperaturePoint.roomId" list="heatRoomList" listKey="id" listValue="houseNo" headerKey="" headerValue="Please select" cssClass="s_sel"
							datatype="*" nullmsg="Please select the apartment number！" errormsg="Please select the apartment number！"></s:select>
            			<input type="text" style="display:none;" name="temperaturePoint.houseNo" value="<s:property value='temperaturePoint.houseNo' />" class="s_input"
            				datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{1,50}$/" sucmsg="Apartment Number Verification Passed！" nullmsg="Please enter Apartment Number！" errormsg="Apartment Number only can be composed of letters,numbers and dashes within 1~50 characters！"/>
            			&nbsp;<span style="color:#FF0000;">*</span>&nbsp;<a href="javascript:void(0)" name="switchLink">other</a>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Concentrator No.</th>
        			<td>
        				<script type="text/javascript">
				       		function reloadConcentrators(projectUID, communityUID, concentratorUID) {
			        			$("select[name='temperaturePoint.concentratorID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/concentratorActionJson!queryConcentratorsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(concentratorUID!=null && concentratorUID!="" && concentratorUID==data[index].id) {
	        								$("select[name='temperaturePoint.concentratorID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].concentratorNo+"</option>");
	        							} else {
	        								$("select[name='temperaturePoint.concentratorID']").append("<option value='"+data[index].id+"'>"+data[index].concentratorNo+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		
			        		$(function(){
			        			$("select[name='temperaturePoint.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='temperaturePoint.communityID']").val();
			        				var concentratorUID = $("select[name='temperaturePoint.concentratorID']").val();
			        				reloadConcentrators(projectUID, communityUID, concentratorUID);
			        			});
			        			
			        			$("select[name='temperaturePoint.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='temperaturePoint.projectID']").val();
			        				var concentratorUID = $("select[name='temperaturePoint.concentratorID']").val();
			        				reloadConcentrators(projectUID, communityUID, concentratorUID);
			        			});
			        		});
        				</script>
	        			<s:select name="temperaturePoint.concentratorID" list="concentratorList" listKey="id" listValue="concentratorNo" headerKey="" headerValue="Please select" cssClass="s_sel"
	        				datatype="*" nullmsg="Please select concentrator no.！" errormsg="Please select concentrator no.！"></s:select>
	            			&nbsp;<span style="color:#FF0000;">*</span>
	            		<div class="Validform_checktip"></div></td>
	            	<th>Temperature Spot No.：</th>
          			<td><input name="seriousNum" type="text" class="s_input" value="<s:property value='temperaturePoint.seriousNum' />" 
          					datatype="/^[0-9a-zA-Z]{1,40}$/" sucmsg="Temperature Spot No. Verification Passed！" nullmsg="Please enter Temperature Spot No.！" errormsg="Temperature Spot No. only can be composed of letters,numbers and dashes within 1~40 characters！"/>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Temperature Spot No. only can be composed of letters,numbers and dashes within 1~40 characters！</div></td>
        		</tr>
        		<tr>
        			<th>Remark：</th>
          			<td colspan="3">
          				<textarea name="remark" cols="45" rows="3"
          					datatype="*1-200" ignore="ignore" errormsg="Invalid input!  please input valid content ,no more than 200pcs character">
          					<s:property value='temperaturePoint.remark' /></textarea>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="button" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
